function Node(value){
    this.value = value;
    this.left = null;
    this.right = null;
}

var a = new Node("a");
var b = new Node("b");
var c = new Node("c");
var d = new Node("d");
var e = new Node("e");
var f = new Node("f");
a.left = b;
a.right = c;
b.left = d;
c.left = e;
c.right = f;

var a2 = new Node("a");
var b2 = new Node("b");
var c2 = new Node("c");
var d2 = new Node("d");
var e2 = new Node("e");
// var f2 = new Node("f");

a2.left = c2;
a2.right = b2;
b2.left = e2;
b2.right = f2;
c2.left = d2;

var diffList = [];
function treeDiff(root1,root2,diffList) {
    if(root1 == root2) return diffList;
    if(root1 == null&&root2 != null){
        diffList.push({type:"新增",origin:null,now:root2});
    }else if(root1 !=null && root2 == null){
        diffList.push({type:"删除",origin:root1,now:null});
    }else if(root1.value != root2.value){
        diffList.push({type:"更新",origin:root1,now:root2});
        treeDiff(root1.left,root2.left,diffList);
        treeDiff(root1.right,root2.right,diffList);
    }else{
        treeDiff(root1.left, root2.left,diffList);
        treeDiff(root1.right, root2.right,diffList);
    }
}

treeDiff(a,a2,diffList);
console.log(diffList);

